package com.cxm.weilai.util;

import java.util.ArrayList;

/**
 * 转义js脚本，阻止其执行
 * @author tao
 */
public class PreScriptInjectionUtil {

    /**
     * 转义js脚本.
     * @param txt  传入值
     * @return String
     */
    public static <E> String HTMLEncode(String txt) {
        new ArrayList<E>();

        String ntxt = txt;
        if (ntxt == null) { return ""; }
        ntxt = ntxt.replace(" ", "&nbsp;");
        ntxt = ntxt.replace("<", "&lt;");
        ntxt = ntxt.replace(">", "&gt;");
        ntxt = ntxt.replace("\"", "&quot;");
        ntxt = ntxt.replace("'", "&#39;");
        ntxt = ntxt.replace("\n", "<br>");

        return ntxt;

    }
}